
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 2016/11/13 1:27:43
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace yncTech.BusinessObjects
{
	/// <summary>
	/// Encapsulates the 'BF_ThirdUnit' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(BFThirdUnit))]	
	[XmlType("BFThirdUnit")]
	public partial class BFThirdUnit : esBFThirdUnit
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new BFThirdUnit();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Decimal thirdUnitID)
		{
			var obj = new BFThirdUnit();
			obj.ThirdUnitID = thirdUnitID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Decimal thirdUnitID, esSqlAccessType sqlAccessType)
		{
			var obj = new BFThirdUnit();
			obj.ThirdUnitID = thirdUnitID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("BFThirdUnitCollection")]
	public partial class BFThirdUnitCollection : esBFThirdUnitCollection, IEnumerable<BFThirdUnit>
	{
		public BFThirdUnit FindByPrimaryKey(System.Decimal thirdUnitID)
		{
			return this.SingleOrDefault(e => e.ThirdUnitID == thirdUnitID);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(BFThirdUnit))]
		public class BFThirdUnitCollectionWCFPacket : esCollectionWCFPacket<BFThirdUnitCollection>
		{
			public static implicit operator BFThirdUnitCollection(BFThirdUnitCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator BFThirdUnitCollectionWCFPacket(BFThirdUnitCollection collection)
			{
				return new BFThirdUnitCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class BFThirdUnitQuery : esBFThirdUnitQuery
	{
		public BFThirdUnitQuery():this("BFThirdUnitQuery")
		{
		}
		public BFThirdUnitQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "BFThirdUnitQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(BFThirdUnitQuery query)
		{
			return BFThirdUnitQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator BFThirdUnitQuery(string query)
		{
			return (BFThirdUnitQuery)BFThirdUnitQuery.SerializeHelper.FromXml(query, typeof(BFThirdUnitQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esBFThirdUnit : esEntity
	{
		public esBFThirdUnit()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Decimal thirdUnitID)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(thirdUnitID);
			else
				return LoadByPrimaryKeyStoredProcedure(thirdUnitID);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Decimal thirdUnitID)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(thirdUnitID);
			else
				return LoadByPrimaryKeyStoredProcedure(thirdUnitID);
		}

		private bool LoadByPrimaryKeyDynamic(System.Decimal thirdUnitID)
		{
			BFThirdUnitQuery query = new BFThirdUnitQuery();
			query.Where(query.ThirdUnitID == thirdUnitID);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Decimal thirdUnitID)
		{
			esParameters parms = new esParameters();
			parms.Add("ThirdUnitID", thirdUnitID);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.ThirdUnitID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? ThirdUnitID
		{
			get
			{
				return base.GetSystemDecimal(BFThirdUnitMetadata.ColumnNames.ThirdUnitID);
			}
			
			set
			{
				if(base.SetSystemDecimal(BFThirdUnitMetadata.ColumnNames.ThirdUnitID, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ThirdUnitID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.Name
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Name
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.Name);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.Name, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.Name);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.CartName
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String CartName
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.CartName);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.CartName, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.CartName);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.Email
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Email
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.Email);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.Email, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.Email);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.Address
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Address
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.Address);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.Address, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.Address);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.Status
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? Status
		{
			get
			{
				return base.GetSystemInt32(BFThirdUnitMetadata.ColumnNames.Status);
			}
			
			set
			{
				if(base.SetSystemInt32(BFThirdUnitMetadata.ColumnNames.Status, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.Status);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.CreatedBy
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String CreatedBy
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.CreatedBy);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.CreatedBy, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.CreatedBy);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.CreatedDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreatedDate
		{
			get
			{
				return base.GetSystemDateTime(BFThirdUnitMetadata.ColumnNames.CreatedDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(BFThirdUnitMetadata.ColumnNames.CreatedDate, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.CreatedDate);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.LastedUpdatedBy
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String LastedUpdatedBy
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.LastedUpdatedBy);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.LastedUpdatedBy, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.LastedUpdatedBy);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.LastedUpdatedDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? LastedUpdatedDate
		{
			get
			{
				return base.GetSystemDateTime(BFThirdUnitMetadata.ColumnNames.LastedUpdatedDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(BFThirdUnitMetadata.ColumnNames.LastedUpdatedDate, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.LastedUpdatedDate);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.ThirdType
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String ThirdType
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.ThirdType);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.ThirdType, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ThirdType);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.ManageUserId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? ManageUserId
		{
			get
			{
				return base.GetSystemDecimal(BFThirdUnitMetadata.ColumnNames.ManageUserId);
			}
			
			set
			{
				if(base.SetSystemDecimal(BFThirdUnitMetadata.ColumnNames.ManageUserId, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ManageUserId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to BF_ThirdUnit.ExtType
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String ExtType
		{
			get
			{
				return base.GetSystemString(BFThirdUnitMetadata.ColumnNames.ExtType);
			}
			
			set
			{
				if(base.SetSystemString(BFThirdUnitMetadata.ColumnNames.ExtType, value))
				{
					OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ExtType);
				}
			}
		}		
		
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "ThirdUnitID": this.str().ThirdUnitID = (string)value; break;							
						case "Name": this.str().Name = (string)value; break;							
						case "CartName": this.str().CartName = (string)value; break;							
						case "Email": this.str().Email = (string)value; break;							
						case "Address": this.str().Address = (string)value; break;							
						case "Status": this.str().Status = (string)value; break;							
						case "CreatedBy": this.str().CreatedBy = (string)value; break;							
						case "CreatedDate": this.str().CreatedDate = (string)value; break;							
						case "LastedUpdatedBy": this.str().LastedUpdatedBy = (string)value; break;							
						case "LastedUpdatedDate": this.str().LastedUpdatedDate = (string)value; break;							
						case "ThirdType": this.str().ThirdType = (string)value; break;							
						case "ManageUserId": this.str().ManageUserId = (string)value; break;							
						case "ExtType": this.str().ExtType = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "ThirdUnitID":
						
							if (value == null || value is System.Decimal)
								this.ThirdUnitID = (System.Decimal?)value;
								OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ThirdUnitID);
							break;
						
						case "Status":
						
							if (value == null || value is System.Int32)
								this.Status = (System.Int32?)value;
								OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.Status);
							break;
						
						case "CreatedDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedDate = (System.DateTime?)value;
								OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.CreatedDate);
							break;
						
						case "LastedUpdatedDate":
						
							if (value == null || value is System.DateTime)
								this.LastedUpdatedDate = (System.DateTime?)value;
								OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.LastedUpdatedDate);
							break;
						
						case "ManageUserId":
						
							if (value == null || value is System.Decimal)
								this.ManageUserId = (System.Decimal?)value;
								OnPropertyChanged(BFThirdUnitMetadata.PropertyNames.ManageUserId);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esBFThirdUnit entity)
			{
				this.entity = entity;
			}
			
	
			public System.String ThirdUnitID
			{
				get
				{
					System.Decimal? data = entity.ThirdUnitID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ThirdUnitID = null;
					else entity.ThirdUnitID = Convert.ToDecimal(value);
				}
			}
				
			public System.String Name
			{
				get
				{
					System.String data = entity.Name;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Name = null;
					else entity.Name = Convert.ToString(value);
				}
			}
				
			public System.String CartName
			{
				get
				{
					System.String data = entity.CartName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CartName = null;
					else entity.CartName = Convert.ToString(value);
				}
			}
				
			public System.String Email
			{
				get
				{
					System.String data = entity.Email;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Email = null;
					else entity.Email = Convert.ToString(value);
				}
			}
				
			public System.String Address
			{
				get
				{
					System.String data = entity.Address;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Address = null;
					else entity.Address = Convert.ToString(value);
				}
			}
				
			public System.String Status
			{
				get
				{
					System.Int32? data = entity.Status;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Status = null;
					else entity.Status = Convert.ToInt32(value);
				}
			}
				
			public System.String CreatedBy
			{
				get
				{
					System.String data = entity.CreatedBy;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedBy = null;
					else entity.CreatedBy = Convert.ToString(value);
				}
			}
				
			public System.String CreatedDate
			{
				get
				{
					System.DateTime? data = entity.CreatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedDate = null;
					else entity.CreatedDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String LastedUpdatedBy
			{
				get
				{
					System.String data = entity.LastedUpdatedBy;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastedUpdatedBy = null;
					else entity.LastedUpdatedBy = Convert.ToString(value);
				}
			}
				
			public System.String LastedUpdatedDate
			{
				get
				{
					System.DateTime? data = entity.LastedUpdatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastedUpdatedDate = null;
					else entity.LastedUpdatedDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String ThirdType
			{
				get
				{
					System.String data = entity.ThirdType;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ThirdType = null;
					else entity.ThirdType = Convert.ToString(value);
				}
			}
				
			public System.String ManageUserId
			{
				get
				{
					System.Decimal? data = entity.ManageUserId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ManageUserId = null;
					else entity.ManageUserId = Convert.ToDecimal(value);
				}
			}
				
			public System.String ExtType
			{
				get
				{
					System.String data = entity.ExtType;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ExtType = null;
					else entity.ExtType = Convert.ToString(value);
				}
			}
			

			private esBFThirdUnit entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return BFThirdUnitMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public BFThirdUnitQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new BFThirdUnitQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(BFThirdUnitQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(BFThirdUnitQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private BFThirdUnitQuery query;		
	}



	[Serializable]
	abstract public partial class esBFThirdUnitCollection : esEntityCollection<BFThirdUnit>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return BFThirdUnitMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "BFThirdUnitCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public BFThirdUnitQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new BFThirdUnitQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(BFThirdUnitQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new BFThirdUnitQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(BFThirdUnitQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((BFThirdUnitQuery)query);
		}

		#endregion
		
		private BFThirdUnitQuery query;
	}



	[Serializable]
	abstract public partial class esBFThirdUnitQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return BFThirdUnitMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "ThirdUnitID": return this.ThirdUnitID;
				case "Name": return this.Name;
				case "CartName": return this.CartName;
				case "Email": return this.Email;
				case "Address": return this.Address;
				case "Status": return this.Status;
				case "CreatedBy": return this.CreatedBy;
				case "CreatedDate": return this.CreatedDate;
				case "LastedUpdatedBy": return this.LastedUpdatedBy;
				case "LastedUpdatedDate": return this.LastedUpdatedDate;
				case "ThirdType": return this.ThirdType;
				case "ManageUserId": return this.ManageUserId;
				case "ExtType": return this.ExtType;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem ThirdUnitID
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.ThirdUnitID, esSystemType.Decimal); }
		} 
		
		public esQueryItem Name
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.Name, esSystemType.String); }
		} 
		
		public esQueryItem CartName
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.CartName, esSystemType.String); }
		} 
		
		public esQueryItem Email
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.Email, esSystemType.String); }
		} 
		
		public esQueryItem Address
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.Address, esSystemType.String); }
		} 
		
		public esQueryItem Status
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.Status, esSystemType.Int32); }
		} 
		
		public esQueryItem CreatedBy
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.CreatedBy, esSystemType.String); }
		} 
		
		public esQueryItem CreatedDate
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.CreatedDate, esSystemType.DateTime); }
		} 
		
		public esQueryItem LastedUpdatedBy
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.LastedUpdatedBy, esSystemType.String); }
		} 
		
		public esQueryItem LastedUpdatedDate
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.LastedUpdatedDate, esSystemType.DateTime); }
		} 
		
		public esQueryItem ThirdType
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.ThirdType, esSystemType.String); }
		} 
		
		public esQueryItem ManageUserId
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.ManageUserId, esSystemType.Decimal); }
		} 
		
		public esQueryItem ExtType
		{
			get { return new esQueryItem(this, BFThirdUnitMetadata.ColumnNames.ExtType, esSystemType.String); }
		} 
		
		#endregion
		
	}


	
	public partial class BFThirdUnit : esBFThirdUnit
	{

		#region FinBoxCollectionByBoxLocation - Zero To Many
		
		static public esPrefetchMap Prefetch_FinBoxCollectionByBoxLocation
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = yncTech.BusinessObjects.BFThirdUnit.FinBoxCollectionByBoxLocation_Delegate;
				map.PropertyName = "FinBoxCollectionByBoxLocation";
				map.MyColumnName = "BoxLocation";
				map.ParentColumnName = "ThirdUnitID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void FinBoxCollectionByBoxLocation_Delegate(esPrefetchParameters data)
		{
			BFThirdUnitQuery parent = new BFThirdUnitQuery(data.NextAlias());

			FinBoxQuery me = data.You != null ? data.You as FinBoxQuery : new FinBoxQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.ThirdUnitID == me.BoxLocation);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_FIN_BOX_REFERENCE_BF_THIRD
		/// </summary>

		[XmlIgnore]
		public FinBoxCollection FinBoxCollectionByBoxLocation
		{
			get
			{
				if(this._FinBoxCollectionByBoxLocation == null)
				{
					this._FinBoxCollectionByBoxLocation = new FinBoxCollection();
					this._FinBoxCollectionByBoxLocation.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("FinBoxCollectionByBoxLocation", this._FinBoxCollectionByBoxLocation);
				
					if (this.ThirdUnitID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._FinBoxCollectionByBoxLocation.Query.Where(this._FinBoxCollectionByBoxLocation.Query.BoxLocation == this.ThirdUnitID);
							this._FinBoxCollectionByBoxLocation.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._FinBoxCollectionByBoxLocation.fks.Add(FinBoxMetadata.ColumnNames.BoxLocation, this.ThirdUnitID);
					}
				}

				return this._FinBoxCollectionByBoxLocation;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._FinBoxCollectionByBoxLocation != null) 
				{ 
					this.RemovePostSave("FinBoxCollectionByBoxLocation"); 
					this._FinBoxCollectionByBoxLocation = null;
					
				} 
			} 			
		}
			
		
		private FinBoxCollection _FinBoxCollectionByBoxLocation;
		#endregion

		#region TSUserInfoCollectionByThirdUnitID - Zero To Many
		
		static public esPrefetchMap Prefetch_TSUserInfoCollectionByThirdUnitID
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = yncTech.BusinessObjects.BFThirdUnit.TSUserInfoCollectionByThirdUnitID_Delegate;
				map.PropertyName = "TSUserInfoCollectionByThirdUnitID";
				map.MyColumnName = "ThirdUnitID";
				map.ParentColumnName = "ThirdUnitID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void TSUserInfoCollectionByThirdUnitID_Delegate(esPrefetchParameters data)
		{
			BFThirdUnitQuery parent = new BFThirdUnitQuery(data.NextAlias());

			TSUserInfoQuery me = data.You != null ? data.You as TSUserInfoQuery : new TSUserInfoQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.ThirdUnitID == me.ThirdUnitID);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_T_S_USER_REFERENCE_BF_THIRD
		/// </summary>

		[XmlIgnore]
		public TSUserInfoCollection TSUserInfoCollectionByThirdUnitID
		{
			get
			{
				if(this._TSUserInfoCollectionByThirdUnitID == null)
				{
					this._TSUserInfoCollectionByThirdUnitID = new TSUserInfoCollection();
					this._TSUserInfoCollectionByThirdUnitID.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("TSUserInfoCollectionByThirdUnitID", this._TSUserInfoCollectionByThirdUnitID);
				
					if (this.ThirdUnitID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._TSUserInfoCollectionByThirdUnitID.Query.Where(this._TSUserInfoCollectionByThirdUnitID.Query.ThirdUnitID == this.ThirdUnitID);
							this._TSUserInfoCollectionByThirdUnitID.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._TSUserInfoCollectionByThirdUnitID.fks.Add(TSUserInfoMetadata.ColumnNames.ThirdUnitID, this.ThirdUnitID);
					}
				}

				return this._TSUserInfoCollectionByThirdUnitID;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._TSUserInfoCollectionByThirdUnitID != null) 
				{ 
					this.RemovePostSave("TSUserInfoCollectionByThirdUnitID"); 
					this._TSUserInfoCollectionByThirdUnitID = null;
					
				} 
			} 			
		}
			
		
		private TSUserInfoCollection _TSUserInfoCollectionByThirdUnitID;
		#endregion

		
		protected override esEntityCollectionBase CreateCollectionForPrefetch(string name)
		{
			esEntityCollectionBase coll = null;

			switch (name)
			{
				case "FinBoxCollectionByBoxLocation":
					coll = this.FinBoxCollectionByBoxLocation;
					break;
				case "TSUserInfoCollectionByThirdUnitID":
					coll = this.TSUserInfoCollectionByThirdUnitID;
					break;	
			}

			return coll;
		}		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "FinBoxCollectionByBoxLocation", typeof(FinBoxCollection), new FinBox()));
			props.Add(new esPropertyDescriptor(this, "TSUserInfoCollectionByThirdUnitID", typeof(TSUserInfoCollection), new TSUserInfo()));
		
			return props;
		}
		
		/// <summary>
		/// Called by ApplyPostSaveKeys 
		/// </summary>
		/// <param name="coll">The collection to enumerate over</param>
		/// <param name="key">"The column name</param>
		/// <param name="value">The column value</param>
		private void Apply(esEntityCollectionBase coll, string key, object value)
		{
			foreach (esEntity obj in coll)
			{
				if (obj.es.IsAdded)
				{
					obj.SetProperty(key, value);
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._FinBoxCollectionByBoxLocation != null)
			{
				Apply(this._FinBoxCollectionByBoxLocation, "BoxLocation", this.ThirdUnitID);
			}
			if(this._TSUserInfoCollectionByThirdUnitID != null)
			{
				Apply(this._TSUserInfoCollectionByThirdUnitID, "ThirdUnitID", this.ThirdUnitID);
			}
		}
		
	}
	



	[Serializable]
	public partial class BFThirdUnitMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected BFThirdUnitMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.ThirdUnitID, 0, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.ThirdUnitID;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 18;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.Name, 1, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.Name;
			c.CharacterMaxLength = 100;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.CartName, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.CartName;
			c.CharacterMaxLength = 100;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.Email, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.Email;
			c.CharacterMaxLength = 100;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.Address, 4, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.Address;
			c.CharacterMaxLength = 120;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.Status, 5, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.Status;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.CreatedBy, 6, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.CreatedBy;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.CreatedDate, 7, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.CreatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.LastedUpdatedBy, 8, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.LastedUpdatedBy;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.LastedUpdatedDate, 9, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.LastedUpdatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.ThirdType, 10, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.ThirdType;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.ManageUserId, 11, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.ManageUserId;
			c.NumericPrecision = 18;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(BFThirdUnitMetadata.ColumnNames.ExtType, 12, typeof(System.String), esSystemType.String);
			c.PropertyName = BFThirdUnitMetadata.PropertyNames.ExtType;
			c.CharacterMaxLength = 30;
			c.IsNullable = true;
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public BFThirdUnitMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string ThirdUnitID = "ThirdUnitID";
			 public const string Name = "Name";
			 public const string CartName = "CartName";
			 public const string Email = "Email";
			 public const string Address = "Address";
			 public const string Status = "Status";
			 public const string CreatedBy = "CreatedBy";
			 public const string CreatedDate = "CreatedDate";
			 public const string LastedUpdatedBy = "LastedUpdatedBy";
			 public const string LastedUpdatedDate = "LastedUpdatedDate";
			 public const string ThirdType = "ThirdType";
			 public const string ManageUserId = "ManageUserId";
			 public const string ExtType = "ExtType";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string ThirdUnitID = "ThirdUnitID";
			 public const string Name = "Name";
			 public const string CartName = "CartName";
			 public const string Email = "Email";
			 public const string Address = "Address";
			 public const string Status = "Status";
			 public const string CreatedBy = "CreatedBy";
			 public const string CreatedDate = "CreatedDate";
			 public const string LastedUpdatedBy = "LastedUpdatedBy";
			 public const string LastedUpdatedDate = "LastedUpdatedDate";
			 public const string ThirdType = "ThirdType";
			 public const string ManageUserId = "ManageUserId";
			 public const string ExtType = "ExtType";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(BFThirdUnitMetadata))
			{
				if(BFThirdUnitMetadata.mapDelegates == null)
				{
					BFThirdUnitMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (BFThirdUnitMetadata.meta == null)
				{
					BFThirdUnitMetadata.meta = new BFThirdUnitMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("ThirdUnitID", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("Name", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CartName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("Email", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("Address", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("Status", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("CreatedBy", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("CreatedDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("LastedUpdatedBy", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("LastedUpdatedDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("ThirdType", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("ManageUserId", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("ExtType", new esTypeMap("nvarchar", "System.String"));			
				
				
				
				meta.Source = "BF_ThirdUnit";
				meta.Destination = "BF_ThirdUnit";
				
				meta.spInsert = "proc_BF_ThirdUnitInsert";				
				meta.spUpdate = "proc_BF_ThirdUnitUpdate";		
				meta.spDelete = "proc_BF_ThirdUnitDelete";
				meta.spLoadAll = "proc_BF_ThirdUnitLoadAll";
				meta.spLoadByPrimaryKey = "proc_BF_ThirdUnitLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private BFThirdUnitMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
